<?php 
namespace app\admin\controller;

use think\Controller;
use think\facade\Validate;

/**
 * 反馈管理
 */
class Feedback extends Controller
{
	/*反馈管理页面*/
	public function index()
	{
		if(request()->isAjax()){

			$map = [];
			$search = $this->request->param('search', '');
			$limit = $this->request->param('limit', 10);
            if ($search) {
                $map[] = ['u.username|u.realname|u.phone', 'like', '%'.$search.'%'];
            }

			$data = model('Feedback')->alias('f')
				->join('user u','f.user_id=u.id','left')
				->field('f.*,u.username,u.realname,u.phone')
				->where($map)
				->order('f.create_time desc')
				->paginate($limit,false,['query'=>$this->request->param()]);

			$this->result(['data' => $data->items(), 'count' => $data->total()], 1, '获取成功', 'json');
		}

		return view();
	}

	/*删除*/
	public function delete()
	{
		$id = input('id');

		$res = model('Feedback')->destroy($id);
		if($res){
			$this->result('',1,'删除成功','json');
		}else{
			$this->result('',0,'删除失败','json');
		}
	}

	//设置状态
	public function setStatus()
	{
		$data = input();

		$res = model('Feedback')->save($data,['id'=>$data['id']]);
		if($res){
			$this->result('',1,'设置成功','json');
		}else{
			$this->result('',0,'设置失败','json');
		}
	}
}

 ?>